import { useAppStore } from '@/store/app';
import { useRouter,RouteRecordRaw } from 'vue-router';

export function setRoutes(){
    const App = useAppStore()
    const router = useRouter()
    let routes:Array<RouteRecordRaw> = []
    if(router){
        if((!App.routes || App.routes.length === 0)){
            routes = router.getRoutes()
            const authRoutes = routes.filter(item => !item.meta.hidden && item.children.length > 0)
            localStorage.setItem("xl-routes",JSON.stringify(authRoutes))
            App.$patch((state) => {
                state.routes = authRoutes
            })
        }else{
            return "router load"
        }
    }else{
        routes = JSON.parse(localStorage.getItem("xl-routes") ||'[]');
        if(routes.length){
            App.$patch((state) => {
                state.routes = routes
            })
        }
        
       
    }
   
} 